/**
 * 音频组件控制
 *
 */
class InnerAudio {
    constructor(options) {
        // this.innerAudioContext = wx.createInnerAudioContext() //创建并返回内部 audio
        this.init = this._init();
    }

    innerAudioContext = wx.createInnerAudioContext() //创建并返回内部 audio

    _init() {
        let _this = this;

        _this.showThis()
        return 'init success'
    }

    setParameter(key, value) { //设置播放器参数
        let _this = this;

        _this.innerAudioContext[key] = value;
    }

    getParameter(key) { //获取播放器属性
        let _this = this;

        return _this.innerAudioContext[key];
    }

    play() { //播放音频
        let _this = this;

        _this.innerAudioContext.play();
        console.log('播放音频')
    }

    pause() { //暂停播放音频
        let _this = this;

        _this.innerAudioContext.pause();
        console.log('暂停播放音频')
    }

    stop() { //停止播放音频
        let _this = this;

        _this.innerAudioContext.stop();
        console.log('停止播放音频')
    }

    seek(time) { //跳转到指定位置，单位 s
        let _this = this;

        _this.innerAudioContext.seek(time);
        console.log('跳转到指定位置')
    }

    destroy() {
        let _this = this;

        _this.innerAudioContext.destroy();
        console.log('销毁当前播放器')
    }

    onCanplay = this.innerAudioContext.onCanplay(function() {
        console.log('音频进入可以播放状态')
    })

    onPlay = this.innerAudioContext.onPlay(function() {
        console.log('音频播放回调')
    })

    onPause = this.innerAudioContext.onPause(function() {
        console.log('音频暂停回调')
    })

    onStop = this.innerAudioContext.onStop(function() {
        console.log('音频停止回调')
    })

    onEnded = this.innerAudioContext.onEnded(function() {
        console.log('音频自然播放结束回调')
    })

    onTimeUpdate = this.innerAudioContext.onTimeUpdate(function() {
        console.log('音频播放进度更新回调')
    })

    onError = this.innerAudioContext.onError(function(err) {
        console.log('音频播放错误回调', err)
    })

    onWaiting = this.innerAudioContext.onWaiting(function() {
        console.log('音频加载中事件回调')
    })

    onSeeking = this.innerAudioContext.onSeeking(function() {
        console.log('音频进行seek操作事件回调')
    })

    onSeeked = this.innerAudioContext.onSeeked(function() {
        console.log('音频完成seek操作事件')
    })

    showThis() {
        console.log('showThis', this)
    }
}

module.exports = new InnerAudio()